/**
 * TODO: Vložit licenci.
 */

package cz.enif.commander.values;

import java.util.ArrayList;
import java.util.List;

/**
 * Hondnota typu TUPLE.
 * 
 * @author enif
 *
 */
final class TupleValue implements IValue 
{
	//// CONSTRUCTORS ////
	
	/**
	 * Konstruktor.
	 * 
	 * @param values Seznam hodnot typu IValue, které se mají vložit do objektu
	 *   TupleValue.
	 */
	public TupleValue(List<IValue> values)
	{
		if (values == null)
		{
			values = new ArrayList<IValue>();
		}

		this.value = values;
	}

	/* (non-Javadoc)
	 * @see cz.enif.commander.values.IValue#getType()
	 */
	@Override
	public ValueType getType() 
	{
		return ValueType.TUPLE;
	}

	/* (non-Javadoc)
	 * @see cz.enif.commander.values.IValue#isBool()
	 */
	@Override
	public boolean isBoolean() 
	{
		return false;
	}

	/* (non-Javadoc)
	 * @see cz.enif.commander.values.IValue#isInt()
	 */
	@Override
	public boolean isInt() 
	{
		return false;
	}

	/* (non-Javadoc)
	 * @see cz.enif.commander.values.IValue#isDouble()
	 */
	@Override
	public boolean isDouble() 
	{
		return false;
	}

	/* (non-Javadoc)
	 * @see cz.enif.commander.values.IValue#isString()
	 */
	@Override
	public boolean isString() 
	{
		return false;
	}
	
	/* (non-Javadoc)
	 * @see cz.enif.commander.values.IValue#isTuple()
	 */
	@Override
	public boolean isTuple() 
	{
		return true;
	}

	/* (non-Javadoc)
	 * @see cz.enif.commander.values.IValue#getBoolValue()
	 */
	@Override
	public boolean getBooleanValue() 
	{
		return false;
	}

	/* (non-Javadoc)
	 * @see cz.enif.commander.values.IValue#getIntValue()
	 */
	@Override
	public int getIntValue() 
	{
		return 0;
	}

	/* (non-Javadoc)
	 * @see cz.enif.commander.values.IValue#getDoubleValue()
	 */
	@Override
	public double getDoubleValue() 
	{
		return 0.0;
	}

	/* (non-Javadoc)
	 * @see cz.enif.commander.values.IValue#getStringValue()
	 */
	@Override
	public String getStringValue() 
	{
		// tuple -> 1/5/7
        if (this.value != null)
        {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < (this.value.size() - 1); i++)
            {
                sb.append(this.value.get(i).toString());
                sb.append('/');
            }

            // pripojime posledni hodnotu
            sb.append(this.value.get(this.value.size() - 1).toString());

            return sb.toString();
        }
        else
        {
            return "<null>";
        }
	}
	
	/* (non-Javadoc)
	 * @see cz.enif.commander.values.IValue#getTupleValue()
	 */
	@Override
	public List<IValue> getTupleValue() 
	{
		return this.value;
	}
	
	/* (non-Javadoc)
	 * @see cz.enif.commander.values.IValue#getLength()
	 */
	@Override
	public int getSize() 
	{
		if (this.value != null) return this.value.size();
		
		return 0;
	}
	
	/* (non-Javadoc)
	 * @see cz.enif.commander.values.IValue#toString()
	 */
    @Override
    public String toString()
    {
        return this.getStringValue();
    }

	//// PRIVATE ////
	
    /** Uložené hodnoty. */
	private final List<IValue> value;
}
